﻿using System;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Web.UI;

namespace ControlExplorer.samples.DataBinding
{
  public partial class Overview : SpreadDemoPage
  {
    protected void Page_Load(object sender, System.EventArgs e)
    {
      if (!Page.IsPostBack)
      {
        //FarPoint.Web.Spread.DefaultSkins.GetAt(1).Apply(FpSpread1.Sheets[0]);
        FpSpread1.CommandBar.BackColor = Color.Wheat;

        //Set the database connection
        DataGrid1.DataSource = GetSuppliers();
        FpSpread1.DataSource = GetSuppliers();

        Page.DataBind();

        //Set the widths
        FpSpread1.ActiveSheetView.Columns[0].Width = 60;
        FpSpread1.ActiveSheetView.Columns[1].Width = 350;
        this.FpSpread1.UseClipboard = false;
      }
    }

    #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
      //
      // CODEGEN: This call is required by the ASP.NET Web Form Designer.
      //
      InitializeComponent();
      base.OnInit(e);
    }

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {

    }
    #endregion

    DataSet GetSuppliers()
    {
      string constr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Northwind.mdb;Persist Security Info=True";
      string sqlstr =
@"SELECT TOP 23 
        SupplierID as 供应商编号, 
        CompanyName as 公司名称, 
        ContactName as 注册名称 , 
        ContactTitle as 职位, 
        Address as 地址, 
        City as 城市, 
        Region as 区域, 
        PostalCode as 邮政编码, 
        Country as 国家, 
        Phone as 电话, 
        Fax as 传真, 
        HomePage as 主页
  FROM suppliers";

      DataSet suppliers = new DataSet();
      using (OleDbConnection myconn = new OleDbConnection(constr))
      {
        OleDbDataAdapter sqlAdapter1 = new OleDbDataAdapter(sqlstr, myconn);
        sqlAdapter1.Fill(suppliers, "Suppliers");
      }

      return suppliers;
    }
  }
}